//
//  JJMainController.m
//  JJPay
//
//  Created by JunJW on 2017/5/12.
//  Copyright © 2017年 JunJW. All rights reserved.
//

#import "JJMainController.h"
#import "UIColor+CZAddition.h"
#import "HMNavigationController.h"
@interface JJMainController ()

@end

@implementation JJMainController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 加载子控制器
    UIViewController *vc1 = [self loadSubControllerWithClassName:@"JJPayController" andTitle:@"支付宝" andImageName:@"TabBar_HomeBar_Spring"];
    UIViewController *vc2 = [self loadSubControllerWithClassName:@"JJShoppingController" andTitle:@"购物车" andImageName:@"TabBar_buy"];
    UIViewController *vc3 = [self loadSubControllerWithClassName:@"JJMapController" andTitle:@"地图" andImageName:@"TabBar_Friends_Spring"];
    UIViewController *vc4 = [self loadSubControllerWithClassName:@"JJMineController" andTitle:@"我的" andImageName:@"TabBar_Assets_Spring"];
    
    
    // 添加到tabbarController中
    self.viewControllers = @[vc1, vc2, vc3, vc4];
    
    // 渲染的颜色
    [self.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blueColor]} forState:UIControlStateNormal];
    [self.tabBar setTintColor:[UIColor redColor]];

}

/**
 加载子控制器
 
 @param className 控制器的类名
 @param title 标题
 @param imageName 图片名字
 @return 已经设置好内容相关的控制器
 */
- (UIViewController *)loadSubControllerWithClassName:(NSString *)className andTitle:(NSString *)title andImageName:(NSString *)imageName {
    
    // className : @"HMHomeController"
    // Clz : HMHomeController
    // vc : HMHomeController对象
    
    Class Clz = NSClassFromString(className);
    UIViewController *vc = [[Clz alloc] init];
    
    // 设置标题
    vc.tabBarItem.title = title;
    vc.navigationItem.title = title;
    
    // 设置图片
    
    [vc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],UITextAttributeFont,[UIColor purpleColor],UITextAttributeTextColor,nil] forState:UIControlStateNormal];
    
    [vc.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],UITextAttributeFont,[UIColor greenColor],UITextAttributeTextColor,nil] forState:UIControlStateSelected];
    
    
    vc.tabBarItem.image = [[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置选中图片
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_Sel",imageName]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 把普通的vc包装上一层nav
    HMNavigationController *nav = [[HMNavigationController alloc] initWithRootViewController:vc];
    
    return nav;
}

@end
